package com.game.autoTool.project.web.common;

import java.awt.*;
import java.awt.event.KeyEvent;

public class KeyboardControl {
    public static void main(String[] args) throws AWTException {
        Robot robot = new Robot();
        
        // 模拟按下和释放单个键
        robot.keyPress(KeyEvent.VK_H);
        robot.keyRelease(KeyEvent.VK_H);
        
        // 模拟组合键（Ctrl+C）
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_C);
        robot.keyRelease(KeyEvent.VK_C);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        
        // 输入字符串
        typeString(robot, "Hello World!");
    }
    
    public static void typeString(Robot robot, String text) {
        for (char c : text.toCharArray()) {
            int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
            if (KeyEvent.CHAR_UNDEFINED == keyCode) {
                continue;
            }
            
            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);
        }
    }
}